/**
 * class to display spaceship
 */
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;


/**
 * @author Master
 * @version $Revision: 1.0 $
 */
public class SpaceshipPanel extends JPanel{
        

        /**
         * Field YIQIAN.
         * (value is 1000)
         */
        private static final int YIQIAN = 1000;

		/**
         * Field BA.
         * (value is 8)
         */
        private static final int BA = 8;

        /**
		 * Field BABAI.
		 * (value is 800)
		 */
		private static final int BABAI = 800;

        /**
         * Field cargoSpace.
         */
        public static JLabel CargoSpace=null,  FuelCap=null;

        /**
         * Constructor for SpaceshipPanel.
         */
        public SpaceshipPanel() {
                setSize(BABAI, YIQIAN);
                setLayout(new GridLayout(BA, BA));
                add(new JLabel("Cargo space: "));
                CargoSpace=new JLabel("" + PlayerInfo.getCargoSpace());
                add(CargoSpace);
                add(new JLabel("upgrade needs: "));
                add(new JLabel("1000"));
                final JButton cargoUpdate=new JButton("Upgrade");
                cargoUpdate.addActionListener(new CargoUpdateListener());
                add(cargoUpdate);
                add(new JLabel(""));
                add(new JLabel("Fuel capacity: "));
                FuelCap=new JLabel("" + PlayerInfo.FuelCapacity);
                add(FuelCap);
                add(new JLabel("upgrade needs: "));
                add(new JLabel("500"));
                final JButton fuelUpdate=new JButton("Upgrade");
                fuelUpdate.addActionListener(new FuelUpdateListener());
                add(fuelUpdate);
                add(new JLabel(""));
                add(new JLabel(""));
                final Button exitButton=new Button("Exit");
                exitButton.addActionListener(new ExitSpaceshipListener());
                add(exitButton);
        }
        
        /**
         * @author Master
         */
        public static class CargoUpdateListener implements ActionListener{
		/**
		 * Field YIQIAN.
		 * (value is 1000)
		 */
		private static final int YIQIAN = 1000;

		/**
		 * Method toString.
		
		 * @return String */
		@Override
		public String toString() {
			return "CargoUpdateListener []";
		}

		/**
		 * Method actionPerformed.
		 * @param e ActionEvent
		
		 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */
		@Override
		public void actionPerformed(ActionEvent e) {
			if (PlayerInfo.Money >= YIQIAN){
				PlayerInfo.setCargoSpace(PlayerInfo.getCargoSpace() + 1);
				CargoSpace.setText("" + PlayerInfo.getCargoSpace());
				PlayerInfo.Money-=YIQIAN;
				MarketPlaceScreen.Money.setText("" + PlayerInfo.Money);
				MarketPlaceScreen.Space.setText("" + PlayerInfo.getCargoAvailable());
				
			}
			else JOptionPane.showMessageDialog( 
					ConfigurationScreen.MyFrame, "not enough money");
		}
		
	}
	
	/**
	 * @author Master
	 */
	public static class FuelUpdateListener implements ActionListener{
		/**
		 * Field WUBAI.
		 * (value is 500)
		 */
		private static final int WUBAI = 500;

		/**
		 * Method toString.
		
		 * @return String */
		@Override
		public String toString() {
			return "FuelUpdateListener []";
		}

		/**
		 * Method actionPerformed.
		 * @param e ActionEvent
		
		 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */
		@Override
		public void actionPerformed(ActionEvent e) {
			if (PlayerInfo.Money >= WUBAI){
				PlayerInfo.FuelCapacity++;
				FuelCap.setText("" + PlayerInfo.FuelCapacity);
				PlayerInfo.Money-=WUBAI;
				MarketPlaceScreen.Money.setText("" + PlayerInfo.Money);
				
			}
			else JOptionPane.showMessageDialog( 
					ConfigurationScreen.MyFrame, "not enough money");
		}
		
	}
}
